/************************************************************
https://anotherssisframework.codeplex.com

Copyright (c) 2014, Allen J. Zyck <sql.architect@outlook.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights 
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
 to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 
AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


************************************************************/

/***********
File: CreateDataWarehouseDB.sql

Description:
This is a SQL script template to create the Data Warehouse database (if it doesn't already
exist). This script creates a small PRIMARY and SECONDARY (default) file group. 
The template provides the ability to modify the name of the database. The default name is DataWarehouse.

IMPORTANT NOTE: 
This is just a placeholder database to represent the staging database.
When creating this for production, this should be sized for the actual database requirements.

You will need to adjust the size of the DataWarehouse database created in this script
in terms of both capacity and number of files to fit your specific application.

If you haven't already, you will also need to optimize file size and the number of tempdb files.
(start with 1 temp db file for each 4 cores)
http://technet.microsoft.com/en-us/library/ms175527(v=sql.105).aspx
http://blogs.msdn.com/b/sqlserverstorageengine/archive/2009/01/04/managing-tempdb-in-sql-server-tempdb-configuration.aspx?Redirected=true
http://www.sqlskills.com/blogs/paul/a-sql-server-dba-myth-a-day-1230-tempdb-should-always-have-one-data-file-per-processor-core/

***********/

USE master
GO

IF NOT EXISTS (SELECT * FROM sys.databases 
   WHERE name = N'<Database_Name, sysname, DataWarehouse>') 
BEGIN
	CREATE DATABASE <Database_Name, sysname, DataWarehouse>
	ON  PRIMARY 
	( 
	  NAME = N'<Database_Name, sysname, DataWarehouse>', 
	  FILENAME = N'<DB_Data_File_Location, sysname, C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\><Database_Name, sysname, DataWarehouse>.mdf', 
	  SIZE = 4096KB , 
	  MAXSIZE = UNLIMITED, 
	  FILEGROWTH = 1024KB 
	 ), 
	 FILEGROUP [DEFAULT]  DEFAULT 
	( 
	  NAME = N'<Database_Name, sysname, Datawarehouse>_Default', 
	  FILENAME = N'<DB_Data_File_Location, sysname, C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\><Database_Name, sysname, DataWarehouse>_Default.ndf', 
	  SIZE = 4096KB , 
	  MAXSIZE = UNLIMITED, 
	  FILEGROWTH = 1024KB 
	 )
	LOG ON 
	( 
	  NAME = N'<Database_Name, sysname, DataWarehouse>_log', 
	  FILENAME = N'<DB_Log_File_Location, sysname, C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\><Database_Name, sysname, DataWarehouse>_log.ldf', 
	  SIZE = 1024KB , 
	  MAXSIZE = 2048GB , 
	  FILEGROWTH = 10%
	)
END
GO

